<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <jsp:include page="/resources/inc/head.jsp" />
    <link href="${basePath}/resources/zheng-admin/plugins/zTree_v3/css/metroStyle/metroStyle.css" rel="stylesheet"/>
</head>
<body>
<form class="layui-form layui-form-pane">
    <div class="layui-form-item">
        <label class="layui-form-label">已选参数</label>
        <div class="layui-input-block">
            <c:forEach var="para" items="${paramList}">
                <input type="checkbox" name="param" title="${para.paramName}" value="${para.id}" checked>
            </c:forEach>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">复制到的分类</label>
        <div class="layui-input-block">
            <div class="zTreeDemoBackground left">
                <ul id="tree" class="ztree"></ul>
            </div>
        </div>
    </div>
</form>

<footer>
    <div class="layui-input-block" style="float:right;margin-right: 20px;margin-top: 20px;">
        <button class="layui-btn" onclick="subCopy()">立即提交</button>
    </div>
</footer>
<jsp:include page="/resources/inc/footer.jsp" />
<script>
    var productCategoryId;
    var setting = {
        check: {
            enable: true,
            chkStyle: "radio",
            radioType: "all"
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };
    function subCopy() {
        var treeObj = $.fn.zTree.getZTreeObj("tree");
        var nodes = treeObj.getCheckedNodes(true);
        if (nodes.length < 1) {
            layer.msg("请选择分类", {icon: 5});
            return;
        }
        var productCategoryId = nodes[0].id;
        var params = $("input[name='param']:checked");
        var paramIds = [];
        if (params.length < 1) {
            layer.msg("至少选择一个复制的参数", {icon: 5});
            return;
        }
        for (var i = 0; i < params.length; i++) {
            paramIds.push(params[i].value);
        }
        var data = {productCategoryId: productCategoryId, paramIds: paramIds};
        var text = "确定将" + paramIds.length + "项参数复制到分类\"" + nodes[0].name + " \"中么？";
        layer.confirm(text, {icon: 3, title: '提示'}, function (index) {
            $.ajax({
                type: 'POST',
                url: "${basePath}/manage/product/param/copy",
                data: JSON.stringify(data),
                contentType: "application/json;charset=utf-8",
                success: function (res) {
                    if (res.data == 0) {
                        layer.msg(res.message, {icon: 5});
                    } else {
                        layer.msg(res.message, {
                            icon: 1,
                            time: 1500 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index);
                            parent.$table.bootstrapTable('refresh');
                        });
                    }
                },
                error: function (res) {
                    layer.msg('复制失败！', {icon: 5});
                }
            });
            layer.close(index);
        });

    }
    $(document).ready(function () {
        initCategoryTree($("#tree"),"${basePath}/manage/product/category/all");
    });
</script>
</body>
</html>
